# -*- coding: utf-8 -*-

"""
Time    :2021/6/15 下午8:34
Author  :chenyang
Email   :chenyang.it@outlook.com
FileName: manage.py
Software: PyCharm
"""
from app import create_app
from flask_script import Manager
from flask_migrate import MigrateCommand
from app.extensions import db
from app.models import Devices, Admin
import uuid

app = create_app()
manager = Manager(app)

# 数据库迁移
# python manage.py db init 执行一遍即可
# python manage.py db migrate 生成迁移计划
# python manage.py db upgrade 执行迁移
# python manage.py db --help 查看帮助
manager.add_command('db', MigrateCommand)


# 执行python manage.py insert_db
@manager.command
def insert_db():
    db.drop_all()
    db.create_all()
    device = Devices(sid='110220330440550660', model='8888', cpu_model='6280', cpu_cores='2*24core',
                     bmc_address='172.31.8.20', purpose='适配', owner='cy', others='你好！我是备注信息！！！')
    db.session.add(device)
    db.session.commit()


@manager.command
def create_admin():
    uid = uuid.uuid4()
    user = Admin(uid, 'test', 'test', 'test@test.com')
    db.session.add(user)
    db.session.commit()


if __name__ == '__main__':
    manager.run()
